<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/10/16 09:51:24 $)
// $RCSfile: wap_manage.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

$template->loadLanguageSection("staff_tickets");
$template->loadLanguageSection("tickets_auditlogs");
require_once ("./modules/tickets/functions_ticketsui.php");
require_once ("./modules/tickets/functions_ticketmain.php");
require_once ("./modules/tickets/functions_search.php");
require_once ("./modules/tickets/functions_ticketcore.php");
require_once ("./modules/tickets/functions_wap.php");


/**
* ###############################################
* TICKET LIST
* ###############################################
*/
if ($eventaction == "list")
{
	$_assigns = getAssignedDepartments(MODULE_TICKETS);

	$_ticketviewid = getDefaultTicketView($_SWIFT["staff"]["staffid"]);

	$_ticketstatusid = $_departmentid = array();

	$_ticketstatusid = getDisplayTicketStatusList();

	$_departmentid = $_assigns;

	if ($_SWIFT["staff"]["tmanage"] == "0")
	{
		exit;
	}


	echo "<?xml version=\"1.0\"?>";
	?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
	<wml>
		<card id="Main" title="Ticket List">
			<p> 

	<?
	if ($_SWIFT["staff"]["tmanage"] != "0")
	{
		renderWAPTicketGrid($_ticketviewid, $_departmentid, $_ticketstatusid);
	}
	?>
		</p> 
	</card>
</wml>

<?




/**
* ###############################################
* VIEW TICKET
* ###############################################
*/
} else if ($eventaction == "viewticket") {
	$_ticketobj =& new TicketMain($_REQUEST["ticketid"]);

	// First get the actual ticket.
	$_loadresult = $_ticketobj->loadTicketDisplay();

	$_ticketobj->lockTicket($_SWIFT["staff"]["staffid"]);
	if (!$_loadresult)
	{
		echo $_SWIFT["language"]["invalidticket"];
		exit;
	}
	$_ticket = &$_ticketobj->ticket;

	echo "<?xml version=\"1.0\"?>";
	?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="Main" title="<?=addslashes($_ticket["subject"])?>">
<p>
<?
	$_limit = 1;

	// Get the current offset for this page
	if (!empty($_REQUEST["offset"]) && is_numeric($_REQUEST["offset"]))
	{
		$_offset = intval($_REQUEST["offset"]);
	} else {
		$_offset = "0";
	}

	$totalreplies = $_ticket["totalreplies"];
	$_posts = $_ticketobj->getTicketPosts($_limit, $_offset, "desc");

	$_pagination = generate_pagination3("index.php?_m=tickets&amp;_a=viewticket&amp;ticketid=".intval($_ticket["ticketid"]), ($totalreplies+1), $_limit, $_offset);

	echo "<anchor>Reply<go href=\"". htmlspecialchars("index.php?_m=tickets&amp;_a=reply&amp;ticketid=".intval($_ticket["ticketid"]))."\"/></anchor><br/>\n";
	echo "<anchor>Ticket List<go href=\"". htmlspecialchars("index.php?_m=tickets&amp;_a=list") ."\"/></anchor><br/>\n";
	echo $_pagination."<br/>\n";

	foreach ($_posts as $key=>$val)
	{
		echo htmlspecialchars($val["fullname"]).": ".htmlspecialchars(strip_tags($val["contents"]))."<BR />";
	}
?>
</p> 
</card>
</wml>
<?




/**
* ###############################################
* REPLY TO A TICKET
* ###############################################
*/
} else if ($eventaction == "reply") {
	$_ticketobj =& new TicketMain($_REQUEST["ticketid"]);

	// First get the actual ticket.
	$_loadresult = $_ticketobj->loadTicketDisplay();

	$_ticketobj->lockTicket($_SWIFT["staff"]["staffid"]);
	if (!$_loadresult)
	{
		echo $_SWIFT["language"]["invalidticket"];
		exit;
	}
	$_ticket = &$_ticketobj->ticket;

	if ($_REQUEST["step"] == 1)
	{
		$ticketpostid = $_ticketobj->createStaffReply($_SWIFT["staff"]["staffid"], $_SWIFT["staff"]["fullname"], $_SWIFT["staff"]["email"], "", $_REQUEST["message"], false, $_ticket["emailqueueid"], "", "", "", "", "", "");

		header("location: index.php?_m=tickets&_a=list");
		exit;
	}

	echo "<?xml version=\"1.0\"?>";
	?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
	<card id="Main" title="Ticket Reply">
		<p> 
<?
	echo "<anchor>View Ticket<go href=\"". htmlspecialchars("index.php?_m=tickets&amp;_a=viewticket&amp;ticketid=".intval($_ticket["ticketid"]))."\"/></anchor><br/>\n";
	echo "<anchor>Ticket List<go href=\"". htmlspecialchars("index.php?_m=tickets&amp;_a=list")."\"/></anchor><br/>\n";
?>

Message: <br/>
<input title="Message" name="message"/> <br/> 
<anchor>SUBMIT REPLY<go href="index.php" method="post"><postfield name="_m" value="tickets"/><postfield name="_a" value="reply"/><postfield name="step" value="1"/><postfield name="ticketid" value="<?=$_ticket["ticketid"]?>"/><postfield name="message" value="$message"/></go></anchor>

</p>
</card>
</wml>
<?
}
?>